Print a list from n times 1 to n times 9


Posted by Christy on 2022-04-19

Description: Write a function named table that accepts a number n and print the list from n times 1 to n times 9

table(1)
1*1 = 1
1*2 = 2
1*3 = 3
1*4 = 4
1*5 = 5
1*6 = 6
1*7 = 7
1*8 = 8
1*9 = 9

table(7)
7*1 = 7
7*2 = 14
7*3 = 21
7*4 = 28
7*5 = 35
7*6 = 42
7*7 = 49
7*8 = 56
7*9 = 63

Answer:

function table(n) {
  for (let i = 1; i <= 9; i++) {
    console.log(n + "*" + i + "=" + n * i);
  }
}

table(3);









Related Posts

Leetcode 刷題 pattern - Fast & Slow Pointer

Leetcode 刷題 pattern - Fast & Slow Pointer

[T-SQL] MSSQL 根據已有的表創建新表

[T-SQL] MSSQL 根據已有的表創建新表

《鳥哥 Linux 私房菜:基礎篇》Chapter 03 - 安裝 CentOS7.x

《鳥哥 Linux 私房菜:基礎篇》Chapter 03 - 安裝 CentOS7.x


Comments